package com.learn.grpc.net;

import io.grpc.Server;
import io.grpc.ServerBuilder;
import lombok.extern.slf4j.Slf4j;


/**
 * @author zongf
 * @since 2023-07-06
 **/
@Slf4j
public class NetServiceGrpcServer {

    public static final int serverPort = 9091;

    public static void main(String[] args) throws Exception{

        //1. 创建 server 构造器
        ServerBuilder<?> serverBuilder = ServerBuilder.forPort(serverPort);

        //2. 添加暴露的服务
        serverBuilder.addService(new NetServiceGrpcImpl());

        //3. 构建 Server
        Server server = serverBuilder.build();

        //4. 启动服务
        server.start();

        log.info("服务启动成功, 端口号:" + serverPort);

        // 等待停止
        server.awaitTermination();

    }
}
